package com.shop.controller;

import com.shop.common.ResponseResult;
import com.shop.entity.Goods;
import com.shop.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@CrossOrigin
@RestController
public class goodsController {
    @Autowired
    private GoodsService goodsService;


    @GetMapping("/goods")
    public ResponseResult selectPage(@RequestParam(required = false)String query,
                                     @RequestParam(required = false)Integer pagenum,
                                     @RequestParam(required = false)Integer pagesize){
        return goodsService.selectPage(pagenum,pagesize,query);
    }
    @PostMapping("/goods")
    public ResponseResult addGoods(@RequestBody Goods goods) throws Exception {
        return  goodsService.addgoods(goods);
    }
    @DeleteMapping("/goods/{id}")
    public ResponseResult deleteGoods(@PathVariable Integer id) throws Exception {
        return goodsService.deleteGoods(id);
    }

    @GetMapping("/goods/{id}")
    public ResponseResult selectOne(@PathVariable Integer id){
        return goodsService.selectOne(id);
    }
    @PutMapping("/goods/{id}")
    public ResponseResult updateGoods(@PathVariable Integer id,@RequestBody Goods goods) throws Exception {
        return goodsService.updateGoods(id, goods);
    }


}
